<% content_for :javascript do %>
  <script type="text/javascript">
        $(".select-all").click(function (e) {
            e.preventDefault();
            $(".checkbox input").attr('checked', true);

        });
  </script>
<% end %>
<%= form_for @account, :html => { :class => "form-horizontal"} do |f| %>
  <% if @account.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@account.errors.count, "error") %> evito que se pueda grabar el usuario:</h2>

      <ul>
      <% @account.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <h3>Datos generales</h3>
  <div class="control-group">
    <%= f.label :name,"Nombre", :class => "control-label" %>
    <div class="controls">
      <%= f.text_field :name %>
    </div>    
  </div>
  <div class="control-group">
    <%= f.label :email,"Correo Electrónico", :class => "control-label" %>
    <div class="controls">
      <%= f.text_field :email %>
    </div>    
  </div>
  <div class="control-group">
    <%= f.label :password,"Contraseña", :class => "control-label" %>
    <div class="controls">
      <%= f.password_field :password %>
    </div>    
  </div>
  <div class="control-group">
    <%= f.label :status, "Activo?", :class => "control-label" %>
    <div class="controls">
      <%= f.check_box :status %>
    </div>    
  </div>
  <div class="control-group">
    <%= f.label :admin, "Es administrador", :class => "control-label" %>
    <div class="controls">
      <%= f.check_box :admin %>
    </div>    
  </div>
  <h3>Permisos de usuarios (<a href="#" class="select-all">Seleccionar todos</a>)</h3>
  <ul style="list-style: none;">
    <% @account_sections.each do |section| %>
        <% if section.categories.count > 0 || section.parent_section_id != nil %>
            <li>
                <h4>Sección <%= section.name %></h4>
                <% section.categories.each do |category| %>
                    <% if category.category_type != 'subcategory' %>
                        <% if category.category_type != 'title' %>
                            <label class="checkbox">
                                <%= check_box_tag "account[category_ids][#{category.id}]", category.name, @account.categories.member?(category)%>
                                <%= category.name %>
                            </label>
                            <% category.subcategories.each do |subcategory| %>
                                <label class="checkbox" style="margin-left: 20px;">
                                    <%= check_box_tag "account[category_ids][#{subcategory.id}]", subcategory.name, @account.categories.member?(subcategory) %>
                                    <%= subcategory.name %>
                                </label>
                            <% end %>
                        <% else %>
                            <label class="checkbox">
                                <%= check_box_tag "account[category_ids][#{category.id}]", category.name, @account.categories.member?(category) %>
                                <h6><%= category.name %></h6>
                            </label>
                        <% end %>
                    <% end %>
                <% end %>
            </li>
        <% end %>
    <% end %>
  </ul>  
  <div class="form-actions" style="padding-left: 20px;">
    <button type="submit" class="btn btn-primary">Grabar</button>
    <%= link_to "Cancelar",accounts_path, :class => "btn btn-warning" %>
  </div>
<% end %>
